import sys

sys.path.append('/Users/chengyanan/PycharmProjects/kuai8_appium')
import multiprocessing

from business.login_business import Login_Business
import unittest
import HTMLTestRunner2
from uitls.server import Server
from uitls.write_user_command import WriteUserCommand


class ParameTestCase(unittest.TestCase):
    def __init__(self, methodName='runTest', parame=None):
        super(ParameTestCase, self).__init__(methodName)
        global parames
        parames = parame


class CaseTest(ParameTestCase):
    @classmethod
    def setUpClass(cls):
        print("setUpclass---->", parames)
        cls.login_business = Login_Business(parames)

    def setUp(self):
        print('this is setup')

    def test_01(self):
        print('test case里面单数', parames)
        self.login_business.login_error()
        # self.assertEqual(1,2,'数据错误')#判断俩个值是否相等
        # self.assertNotEqual(1,1,'相等了')#判断俩个值不想等
        # flag = False
        # # self.assertTrue(flag)#判断值是否为True
        # self.assertFalse(flag)
        # print('this is case01')

    # @unittest.skip('CaseTest')
    def test_02(self):
        self.login_business.login_pass()

    @classmethod
    def tearDownClass(cls):
        print('this is teardowm')


def appium_init():
    server = Server()
    server.main()


def get_suite(i):
    print("get_suite里面的", i)
    suite = unittest.TestSuite()  # 声明一个罐子，装case
    suite.addTest(CaseTest('test_01', parame=i))  # 添加例子1
    suite.addTest(CaseTest('test_02', parame=i))  # 添加例子2
    # unittest.TextTestRunner().run(suite)  # 执行罐子的例子
    html_file = '/Users/chengyanan/PycharmProjects/kuai8_appium/report/report' + str(i) + '.html'
    fp = open(html_file, 'wb')
    HTMLTestRunner2.HTMLTestRunner(stream=fp).run(suite)
    fp.close()


def get_count():
    write_user_file = WriteUserCommand()
    count = write_user_file.get_file_Lines()
    return count


if __name__ == '__main__':
    appium_init()
    threads = []
    for i in range(get_count()):
        print(i)
        t = multiprocessing.Process(target=get_suite, args=(i,))
        threads.append(t)

    for j in threads:
        j.start()
